mm: dirty page accounting hole
Subsystems (2)
RFC PATCH 1/1 mm: dirty page accounting hole
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...
mm/rmap.c +1 -1
@@ -481,7 +481,7 @@ static int page_mkclean_file(struct addrspin_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);
Quoted 14 lines · Nick Piggin
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_SHAREDvma. 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 longerVM_SHARED. The pte is still dirty.Then
clear_page_dirty_for_iois called and leaves that pte dirty and cleans the page. It never gets cleaned until munmap, so msync and writeout accounting are broken.
Quoted 5 lines
I have a fix which just scans
VM_SHAREDtoVM_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 (usingpage_mkwriteand dirty accounting),
Ooh, nice!
Quoted 9 lines
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_mkwritelocking scheme, which was naturally ignored when I brought it up during reviewing those patches. I digress...
Yes, I remember you bringing that up, and later too when you did those fault patches. I assumed you were 'working' on it.
Quoted 1 line
Anyway, here's a patch to fix this first particular issue...
Looks good.
Quoted 6 lines
Index:
linux-2.6/mm/rmap.c
===================================================================
mm/rmap.c static int page_mkclean_file(struct addr · line 487
Quoted 8 lines
mm/rmap.c +1
-1@@ -481,7 +481,7 @@ static int page_mkclean_file(struct addrspin_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);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 14 lines · Peter Zijlstra
Quoted 13 lines · Nick Piggin
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_SHAREDvma. 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 longerVM_SHARED. The pte is still dirty.Then
clear_page_dirty_for_iois called and leaves that pte dirty and cleans the page. It never gets cleaned until munmap, so msync and writeout accounting are broken.
Quoted 7 lines
Quoted 5 lines
I have a fix which just scans
VM_SHAREDtoVM_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 (usingpage_mkwriteand dirty accounting),Ooh, nice!
Thanks for confirming.
Quoted 5 lines
Quoted 5 lines
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.
Quoted 7 lines
Quoted 4 lines
There are several other problems I've also run into, including a fundamentally indadequate
page_mkwritelocking scheme, which was naturally ignored when I brought it up during reviewing those patches. I digress...Yes, I remember you bringing that up, and later too when you did those fault patches. I assumed you were 'working' on it.
Oh that wasn't aimed at you, sorry ;) It is our general... "process" of development. I mean, there is apparently some impending apocolypse due to our scarcity of review bandwidth, so ignoring any review is by definition insignificant.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Nick Piggin
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_SHAREDvma. 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 longerVM_SHARED. The pte is still dirty.
I don't think you've got that right yet.
mprotect can of course change vma->vm_flags to take VM_WRITE off, making vma no longer writeable; but it shouldn't be touching VM_SHARED. And a quick check with debugger confirms that.
It's precisely because of mprotect that page_mkclean_one tests VM_SHARED not VM_WRITE. Changing that to VM_MAYSHARE, as in your patch below, should make no difference to correctness; but would potentially make its loop less efficient (it would also go off to check MAP_SHARED, PROT_READ, fd readonly mappings unnecessarily).
Perhaps there's somewhere else that clears VM_SHARED by mistake? Or another path through mprotect which does so? I haven't checked further, hoping this will jolt you into a different realization.
Quoted 5 lines
Then
clear_page_dirty_for_iois called and leaves that pte dirty and cleans the page. It never gets cleaned until munmap, so msync and writeout accounting are broken.
Quoted 9 lines
I have a fix which just scans
VM_SHAREDtoVM_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 (usingpage_mkwriteand 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.
While I disagree with the patch itself, and don't understand the details of what you're working on there, I certainly agree that it's better for mprotect not to set the pages dirty: at present (on some arches, in most cases? it changes from time to time) change_pte_range is an operation on ptes which doesn't have to mess with struct pages.
Quoted 5 lines
There are several other problems I've also run into, including a fundamentally indadequate
page_mkwritelocking scheme, which was naturally ignored when I brought it up during reviewing those patches. I digress...
Unsatisfactory, yes, sorry about that;
but no, you're not "naturally ignored".
Quoted 2 lines
Anyway, here's a patch to fix this first particular issue...
Could you please go back to inlining your patches?
Thanks,
Hugh
Quoted 6 lines
Index:
linux-2.6/mm/rmap.c
===================================================================
mm/rmap.c static int page_mkclean_file(struct addr · line 487
Quoted 8 lines
mm/rmap.c +1
-1@@ -481,7 +481,7 @@ static int page_mkclean_file(struct addrspin_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);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 21 lines · Hugh Dickins
Quoted 7 lines · Nick Piggin
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_SHAREDvma. 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 longerVM_SHARED. The pte is still dirty.I don't think you've got that right yet.
mprotect can of course change
vma->vm_flagsto takeVM_WRITEoff, making vma no longer writeable; but it shouldn't be touchingVM_SHARED. And a quick check with debugger confirms that.It's precisely because of mprotect that
page_mkclean_onetestsVM_SHAREDnotVM_WRITE. Changing that toVM_MAYSHARE, as in your patch below, should make no difference to correctness; but would potentially make its loop less efficient (it would also go off to checkMAP_SHARED,PROT_READ, fd readonly mappings unnecessarily).
Quoted 3 lines
Perhaps there's somewhere else that clears
VM_SHAREDby mistake? Or another path through mprotect which does so? I haven't checked further, hoping this will jolt you into a different realization.
You are right, I cannot find a path through mprotect that unsets VM_SHARED either.
Something which I failed to validate this morning.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Hugh Dickins
Quoted 6 lines · Nick Piggin
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_SHAREDvma. 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 longerVM_SHARED. The pte is still dirty.
Quoted 5 lines
I don't think you've got that right yet.
mprotect can of course change
vma->vm_flagsto takeVM_WRITEoff, making vma no longer writeable; but it shouldn't be touchingVM_SHARED. And a quick check with debugger confirms that.
Drat, yes, I must have been thinking of VM_WRITE vs VM_MAYWRITE.
Quoted 9 lines
It's precisely because of mprotect that
page_mkclean_onetestsVM_SHAREDnotVM_WRITE. Changing that toVM_MAYSHARE, as in your patch below, should make no difference to correctness; but would potentially make its loop less efficient (it would also go off to checkMAP_SHARED,PROT_READ, fd readonly mappings unnecessarily).Perhaps there's somewhere else that clears
VM_SHAREDby mistake? Or another path through mprotect which does so? I haven't checked further, hoping this will jolt you into a different realization.
Will have to dig further... Thanks for the tip.
Quoted 14 lines
Quoted 4 lines
Then
clear_page_dirty_for_iois called and leaves that pte dirty and cleans the page. It never gets cleaned until munmap, so msync and writeout accounting are broken.Quoted 9 lines
I have a fix which just scans
VM_SHAREDtoVM_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 (usingpage_mkwriteand 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.
Quoted 5 lines
While I disagree with the patch itself, and don't understand the details of what you're working on there, I certainly agree that it's better for mprotect not to set the pages dirty: at present (on some arches, in most cases? it changes from time to time)
change_pte_rangeis an operation on ptes which doesn't have to mess with struct pages.
Right. For me, it gets a bit messy because we'd really like to hold the page lock there (like clear_page_dirty_for_io) in order to be able to get reasonable synchronization between page faults and pte cleaning...
Quoted 11 lines
Quoted 4 lines
There are several other problems I've also run into, including a fundamentally indadequate
page_mkwritelocking scheme, which was naturally ignored when I brought it up during reviewing those patches. I digress...Unsatisfactory, yes, sorry about that;
but no, you're not "naturally ignored".Quoted 1 line
Anyway, here's a patch to fix this first particular issue...
Could you please go back to inlining your patches?
OK I'll try.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · Nick Piggin
Quoted 8 lines · Hugh Dickins
Quoted 6 lines · Nick Piggin
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_SHAREDvma. 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 longerVM_SHARED. The pte is still dirty.
Quoted 7 lines
Quoted 5 lines
I don't think you've got that right yet.
mprotect can of course change
vma->vm_flagsto takeVM_WRITEoff, making vma no longer writeable; but it shouldn't be touchingVM_SHARED. And a quick check with debugger confirms that.Drat, yes, I must have been thinking of
VM_WRITEvsVM_MAYWRITE.
And indeed I was able to reproduce the problem with my "fix" applied too, after refining the test case to be more reproduceable...
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>