Re: mm snapshot broken-out-2007-03-18-02-44.tar.gz uploaded

From: Nick Piggin
Date: Tue Mar 20 2007 - 01:19:24 EST


Nick Piggin wrote:
Andrew Morton wrote:

On Tue, 20 Mar 2007 13:47:53 +1100 Nick Piggin <nickpiggin@xxxxxxxxxxxx> wrote:


Andrew Morton wrote:


Hang on a sec... I'll try fixing the thing before you next make a
release.



Too late. hot-fixes/ awaits thee.


Awww... well thanks very much Michal for reporting the bug, I reproduced
it easily and it turns out to be a typo.

In my testing I never had a lot of writeout going on, so most of the pages
will have been truncated in the first loop...

Also, noticed another problem in the same general area. Andrew you were
indeed right to question the removal of that unmap_mapping_range call,
but I think even it alone it wasn't enough...

--
SUSE Labs, Novell Inc.
The nopage vs invalidate race fix patch did not take care of truncating
private COW pages. Mind you, I'm pretty sure this was previously racy
even for regular truncate, not to mention vmtruncate_range.

Anyway, fix that omission.

Index: linux-2.6/mm/memory.c
===================================================================
--- linux-2.6.orig/mm/memory.c
+++ linux-2.6/mm/memory.c
@@ -1905,7 +1905,18 @@ int vmtruncate(struct inode * inode, lof
if (IS_SWAPFILE(inode))
goto out_busy;
i_size_write(inode, offset);
+
+ /*
+ * unmap_mapping_range is called twice, first simply for efficiency
+ * so that truncate_inode_pages does fewer single-page unmaps. However
+ * after this first call, and before truncate_inode_pages finishes,
+ * it is possible for private pages to be COWed, which remain after
+ * truncate_inode_pages finishes, hence the second unmap_mapping_range
+ * call must be made for correctness.
+ */
+ unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
truncate_inode_pages(mapping, offset);
+ unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
goto out_truncate;

do_expand:
@@ -1943,7 +1954,9 @@ int vmtruncate_range(struct inode *inode

mutex_lock(&inode->i_mutex);
down_write(&inode->i_alloc_sem);
+ unmap_mapping_range(mapping, offset, (end - offset), 1);
truncate_inode_pages_range(mapping, offset, end);
+ unmap_mapping_range(mapping, offset, (end - offset), 1);
inode->i_op->truncate_range(inode, offset, end);
up_write(&inode->i_alloc_sem);
mutex_unlock(&inode->i_mutex);