linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [rfc][patch] mm: dirty page accounting hole
@ 2008-08-12  5:58 Nick Piggin
  2008-08-12  6:50 ` Peter Zijlstra
  2008-08-12 11:15 ` Hugh Dickins
  0 siblings, 2 replies; 7+ messages in thread
From: Nick Piggin @ 2008-08-12  5:58 UTC (permalink / raw)
  To: linux-mm; +Cc: Dickins, Hugh, Zijlstra, Peter

[-- Attachment #1: Type: text/plain, Size: 1299 bytes --]

Hi,

I think I'm running into a hole in dirty page accounting...

What seems to be happening is that a page gets written to via a
VM_SHARED vma. We then set the pte dirty, then mark the page dirty.
Next, mprotect changes the vma so it is no longer writeable so it
is no longer VM_SHARED. The pte is still dirty.

Then clear_page_dirty_for_io is called and leaves that pte dirty
and cleans the page. It never gets cleaned until munmap, so msync
and writeout accounting are broken.

I have a fix which just scans VM_SHARED to VM_MAYSHARE. The other
way I tried is to clear the dirty and write bits and set the page
dirty in mprotect. The problem with that for me is that I'm trying
to rework the vm/fs layer so we never have to allocate data to
write out dirty pages (using page_mkwrite and dirty accounting),
and so this still leaves me with a window where the vma flags are
changed but before the pte is marked clean, in which time the page
is still dirty but it may have its metadata freed because it
doesn't look dirty.

There are several other problems I've also run into, including a
fundamentally indadequate page_mkwrite locking scheme, which was
naturally ignored when I brought it up during reviewing those
patches. I digress...

Anyway, here's a patch to fix this first particular issue...

[-- Attachment #2: mm-dirty-account-fix.patch --]
[-- Type: text/x-diff, Size: 469 bytes --]

Index: linux-2.6/mm/rmap.c
===================================================================
--- linux-2.6.orig/mm/rmap.c
+++ linux-2.6/mm/rmap.c
@@ -481,7 +481,7 @@ static int page_mkclean_file(struct addr
 
 	spin_lock(&mapping->i_mmap_lock);
 	vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, pgoff, pgoff) {
-		if (vma->vm_flags & VM_SHARED)
+		if (vma->vm_flags & VM_MAYSHARE)
 			ret += page_mkclean_one(page, vma);
 	}
 	spin_unlock(&mapping->i_mmap_lock);

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-08-12 13:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-12  5:58 [rfc][patch] mm: dirty page accounting hole Nick Piggin
2008-08-12  6:50 ` Peter Zijlstra
2008-08-12  7:06   ` Nick Piggin
2008-08-12 11:15 ` Hugh Dickins
2008-08-12 11:30   ` Peter Zijlstra
2008-08-12 11:53   ` Nick Piggin
2008-08-12 13:17     ` Nick Piggin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox