Skip to contentSkip to conversation

ext4: Add WARN_ON on unmapped dirty buffer_heads in writepage

PATCH In review Aneesh Kumar K.V 2 participants 2 messages May 28, 2009 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: Add WARN_ON on unmapped dirty buffer_heads in writepage

Now we have block_lock_hole_extend clearing the dirty flag of buffer_heads outside i_size we should not find buffer_heads which are unmapped and dirty in writepage. If we find do a WARN_ON. We can still continue because block_write_full page look at the mapped flag only.

Following sequence of events would result in the above condition.
1) truncate(f, 1024)
2) mmap(f, 0, 4096)
3) a[0] = 'a'
4) truncate(f, 4096)
5) writepage(...)

After step 3 we would have unmapped buffer_heads outside i_size. After step 4 we would have unmapped buffer_heads within i_size.

Now that truncate is calling block_lock_hole_extend which in turn is clearing the dirty flag, we can safely assume that we won't find unmapped dirty buffer_heads in write page. If we did find one we should find out why.

---
 fs/ext4/inode.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
fs/ext4/inode.c +13 -0
index f6f2202..ca26bdd 100644
@@ -2509,6 +2509,11 @@ static int __ext4_journalled_writepage(struct page *page,
 	return ret;
 }
 
+static int ext4_bh_unmapped_and_dirty(handle_t *handle, struct buffer_head *bh)
+{
+	return (!buffer_mapped(bh)) && buffer_dirty(bh);
+}
+
 /*
  * Note that we don't need to start a transaction unless we're journaling data
  * because we should have holes filled from ext4_page_mkwrite(). We even don't
@@ -2622,6 +2627,14 @@ static int ext4_writepage(struct page *page,
 		/* now mark the buffer_heads as dirty and uptodate */
 		block_commit_write(page, 0, len);
 	}
+	/*
+	 * There should not be any unmapped and dirty
+	 * buffer_heads at this point. Look at block_lock_hole_extend
+	 * for more info. If we find one print more info
+	 */
+	 WARN(walk_page_buffers(NULL, page_bufs, 0, len, NULL,
+				 ext4_bh_unmapped_and_dirty),
+		 "Unmapped dirty buffer_heads found in %s\n", __func__);
 
 	if (PageChecked(page) && ext4_should_journal_data(inode)) {
 		/*
Signature · 1 line
1.6.3.1.145.gb74d77
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Aneesh Kumar K.V

Now we have block_lock_hole_extend clearing the dirty flag of buffer_heads outside i_size we should not find buffer_heads which are unmapped and dirty in writepage. If we find do a WARN_ON. We can still continue because block_write_full page look at the mapped flag only.

Following sequence of events would result in the above condition.
1) truncate(f, 1024)
2) mmap(f, 0, 4096)
3) a[0] = 'a'
4) truncate(f, 4096)
5) writepage(...)

Quoted 7 lines

After step 3 we would have unmapped buffer_heads outside i_size. After step 4 we would have unmapped buffer_heads within i_size.

Now that truncate is calling block_lock_hole_extend which in turn is clearing the dirty flag, we can safely assume that we won't find unmapped dirty buffer_heads in write page. If we did find one we should find out why.

Thanks. Apart from one coding-style nitpick, you can add:

Honza

Quoted 11 lines
---
 fs/ext4/inode.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
fs/ext4/inode.c +0 -0
index f6f2202..ca26bdd 100644

fs/ext4/inode.c static int __ext4_journalled_writepage(struct page *page, · line 2514

Quoted 6 lines
fs/ext4/inode.c +3 -0
@@ -2509,6 +2509,11 @@ static int __ext4_journalled_writepage(struct page *page,
 	return ret;
 }
 
+static int ext4_bh_unmapped_and_dirty(handle_t *handle, struct buffer_head *bh)
+{
+	return (!buffer_mapped(bh)) && buffer_dirty(bh);

^ ^
looks a bit strange

Quoted 23 lines
fs/ext4/inode.c +10 -0
+}
+
 /*
  * Note that we don't need to start a transaction unless we're journaling data
  * because we should have holes filled from ext4_page_mkwrite(). We even don't
@@ -2622,6 +2627,14 @@ static int ext4_writepage(struct page *page,
 		/* now mark the buffer_heads as dirty and uptodate */
 		block_commit_write(page, 0, len);
 	}
+	/*
+	 * There should not be any unmapped and dirty
+	 * buffer_heads at this point. Look at block_lock_hole_extend
+	 * for more info. If we find one print more info
+	 */
+	 WARN(walk_page_buffers(NULL, page_bufs, 0, len, NULL,
+				 ext4_bh_unmapped_and_dirty),
+		 "Unmapped dirty buffer_heads found in %s\n", __func__);
 
 	if (PageChecked(page) && ext4_should_journal_data(inode)) {
 		/*
Signature · 1 line
1.6.3.1.145.gb74d77
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR