Skip to contentSkip to conversation

jfs: clear PAGECACHE_TAG_DIRTY for no-write pages

PATCH Peter Zijlstra 3 participants 8 messages Dec 28, 2007 – Dec 29, 2007 3 messages not in the archive JFS filesystem

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): E1J8AC5-0002BE-RP@localhost

#1 lore raw
Quoted 27 lines · Fengguang Wu

Andrew,

This patch fixed the 'pdflush stuck in D state' bug

        http://bugzilla.kernel.org/show_bug.cgi?id=9291

and should be pushed to mainline ASAP.
---

When JFS decides to drop a dirty metapage, it simply clears the META_dirty bit and leave alone the PG_dirty and PAGECACHE_TAG_DIRTY bits.

When such no-write page goes to metapage_writepage(), the `relic' PAGECACHE_TAG_DIRTY tag should be cleared, to prevent pdflush from repeatedly trying to sync them.

Also, avoid the redirty when a bio submission is planned.

---

+++ b/fs/jfs/jfs_metapage.c

(quoted diff) +0 -1
@@ -449,9 +450,15 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
 			goto dump_bio;
 
 		submit_bio(WRITE, bio);
-	}

Review static int metapage_writepage(struct page *page, struct writeback_control *wbc) · line 461

Quoted 10 lines
(quoted diff) +8 -1
-	if (redirty)
+	} else if (redirty) {
 		redirty_page_for_writepage(wbc, page);
+	} else {
+		write_lock_irq(&mapping->tree_lock);
+		radix_tree_tag_clear(&mapping->page_tree,
+				page_index(page),
+				PAGECACHE_TAG_DIRTY);
+		write_unlock_irq(&mapping->tree_lock);
+	}

I'm not liking this open-coded tag_clear, although I currently fail to come up with a nice solution.

#2 lore raw
Quoted 27 lines · Peter Zijlstra
Quoted 25 lines · Fengguang Wu

Andrew,

This patch fixed the 'pdflush stuck in D state' bug

        http://bugzilla.kernel.org/show_bug.cgi?id=9291

and should be pushed to mainline ASAP.
---

When JFS decides to drop a dirty metapage, it simply clears the META_dirty bit and leave alone the PG_dirty and PAGECACHE_TAG_DIRTY bits.

When such no-write page goes to metapage_writepage(), the `relic' PAGECACHE_TAG_DIRTY tag should be cleared, to prevent pdflush from repeatedly trying to sync them.

Also, avoid the redirty when a bio submission is planned.

---

+++ b/fs/jfs/jfs_metapage.c

(quoted diff) +0 -0
@@ -449,9 +450,15 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
 			goto dump_bio;
 
Quoted 15 lines

Review static int metapage_writepage(struct page *page, struct writeback_control *wbc) · line 461

Quoted 12 lines
(quoted diff) +8 -2
 		submit_bio(WRITE, bio);
-	}
-	if (redirty)
+	} else if (redirty) {
 		redirty_page_for_writepage(wbc, page);
+	} else {
+		write_lock_irq(&mapping->tree_lock);
+		radix_tree_tag_clear(&mapping->page_tree,
+				page_index(page),
+				PAGECACHE_TAG_DIRTY);
+		write_unlock_irq(&mapping->tree_lock);
+	}

I'm not liking this open-coded tag_clear, although I currently fail to come up with a nice solution.

Another option is to release/drop such pages ASAP. But what if the metapage_writepage() is called even before we have the chance to release it?

#3 lore raw
In reply to Peter Zijlstra
Quoted 26 lines · Peter Zijlstra
Quoted 25 lines · Fengguang Wu

Andrew,

This patch fixed the 'pdflush stuck in D state' bug

        http://bugzilla.kernel.org/show_bug.cgi?id=9291

and should be pushed to mainline ASAP.
---

When JFS decides to drop a dirty metapage, it simply clears the META_dirty bit and leave alone the PG_dirty and PAGECACHE_TAG_DIRTY bits.

When such no-write page goes to metapage_writepage(), the `relic' PAGECACHE_TAG_DIRTY tag should be cleared, to prevent pdflush from repeatedly trying to sync them.

Also, avoid the redirty when a bio submission is planned.

---

+++ b/fs/jfs/jfs_metapage.c

(quoted diff) +0 -0
@@ -449,9 +450,15 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
 			goto dump_bio;
 
Quoted 15 lines

Review static int metapage_writepage(struct page *page, struct writeback_control *wbc) · line 461

Quoted 12 lines
(quoted diff) +8 -2
 		submit_bio(WRITE, bio);
-	}
-	if (redirty)
+	} else if (redirty) {
 		redirty_page_for_writepage(wbc, page);
+	} else {
+		write_lock_irq(&mapping->tree_lock);
+		radix_tree_tag_clear(&mapping->page_tree,
+				page_index(page),
+				PAGECACHE_TAG_DIRTY);
+		write_unlock_irq(&mapping->tree_lock);
+	}

I'm not liking this open-coded tag_clear, although I currently fail to come up with a nice solution.

I'm looking at __block_write_full_page() for guidance. The situation here is similar to writing a page where all the bufferheads are clean. __block_write_full_page() always calls set_page_writeback(page), and then, if no I/O is initiated, immediately calls end_page_writeback(page).

I'll put together a patch for testing.

Thanks,
Shaggy

Signature · 2 lines
David Kleikamp
IBM Linux Technology Center
#4 lore raw
Quoted 5 lines · Dave Kleikamp
Quoted 2 lines · Peter Zijlstra

I'm not liking this open-coded tag_clear, although I currently fail to come up with a nice solution.

Quoted 7 lines

I'm looking at __block_write_full_page() for guidance. The situation here is similar to writing a page where all the bufferheads are clean. __block_write_full_page() always calls set_page_writeback(page), and then, if no I/O is initiated, immediately calls end_page_writeback(page).

I'll put together a patch for testing.

Here it is, compile-test only so far. I borrowed some of the changeset comments from Fengguang.

JFS: clear PAGECACHE_TAG_DIRTY for no-write pages

When JFS decides to drop a dirty metapage, it simply clears the META_dirty bit and leave alone the PG_dirty and PAGECACHE_TAG_DIRTY bits.

When such no-write page goes to metapage_writepage(), the `relic' PAGECACHE_TAG_DIRTY tag should be cleared, to prevent pdflush from repeatedly trying to sync them. This is done through set_page_writeback(), so call it should be called in all cases. If no I/O is initiated, end_page_writeback() should be called immediately.

This is how __block_write_full_page() does things.

---

fs/jfs/jfs_metapage.c +8 -3
diff -Nurp linux-2.6.24-rc6-git5/fs/jfs/jfs_metapage.c linux/fs/jfs/jfs_metapage.c
@@ -360,6 +360,7 @@ static int metapage_writepage(struct pag
 	struct metapage *mp;
 	int redirty = 0;
 	sector_t lblock;
+	int nr_underway = 0;
 	sector_t pblock;
 	sector_t next_block = 0;
 	sector_t page_start;
@@ -371,6 +372,7 @@ static int metapage_writepage(struct pag
 		     (PAGE_CACHE_SHIFT - inode->i_blkbits);
 	BUG_ON(!PageLocked(page));
 	BUG_ON(PageWriteback(page));
+	set_page_writeback(page);
 
 	for (offset = 0; offset < PAGE_CACHE_SIZE; offset += PSIZE) {
 		mp = page_to_mp(page, offset);
@@ -413,11 +415,10 @@ static int metapage_writepage(struct pag
 			if (!bio->bi_size)
 				goto dump_bio;
 			submit_bio(WRITE, bio);
+			nr_underway++;
 			bio = NULL;
-		} else {
-			set_page_writeback(page);
+		} else
 			inc_io(page);
-		}
 		xlen = (PAGE_CACHE_SIZE - offset) >> inode->i_blkbits;
 		pblock = metapage_get_blocks(inode, lblock, &xlen);
 		if (!pblock) {
@@ -449,12 +450,16 @@ static int metapage_writepage(struct pag
 			goto dump_bio;
 
 		submit_bio(WRITE, bio);
+		nr_underway++;
 	}
 	if (redirty)
 		redirty_page_for_writepage(wbc, page);
 
 	unlock_page(page);
 
+	if (nr_underway == 0)
+		end_page_writeback(page);
+
 	return 0;
 add_failed:
 	/* We should never reach here, since we're only adding one vec */
Signature · 2 lines
David Kleikamp
IBM Linux Technology Center
Reviewed-by
#5 lore raw
Quoted 14 lines · Dave Kleikamp

---

diff -Nurp linux-2.6.24-rc6-git5/fs/jfs/jfs_metapage.c linux/fs/jfs/jfs_metapage.c

fs/jfs/jfs_metapage.c +1 -0
@@ -360,6 +360,7 @@ static int metapage_writepage(struct pag
 	struct metapage *mp;
 	int redirty = 0;
 	sector_t lblock;
+	int nr_underway = 0;
 	sector_t pblock;
 	sector_t next_block = 0;
 	sector_t page_start;

fs/jfs/jfs_metapage.c static int metapage_writepage(struct pag · line 374

Quoted 3 lines
fs/jfs/jfs_metapage.c +0 -0
@@ -371,6 +372,7 @@ static int metapage_writepage(struct pag
 		     (PAGE_CACHE_SHIFT - inode->i_blkbits);
 	BUG_ON(!PageLocked(page));
 	BUG_ON(PageWriteback(page));

This line should be moved below:

Quoted 20 lines
fs/jfs/jfs_metapage.c +1 -0
+	set_page_writeback(page);
 
 
 	for (offset = 0; offset < PAGE_CACHE_SIZE; offset += PSIZE) {
fs/jfs/jfs_metapage.c +2 -3
 		mp = page_to_mp(page, offset);
@@ -413,11 +415,10 @@ static int metapage_writepage(struct pag
 			if (!bio->bi_size)
 				goto dump_bio;
 			submit_bio(WRITE, bio);
+			nr_underway++;
 			bio = NULL;
-		} else {
-			set_page_writeback(page);
+		} else
 			inc_io(page);
-		}
 		xlen = (PAGE_CACHE_SIZE - offset) >> inode->i_blkbits;
 		pblock = metapage_get_blocks(inode, lblock, &xlen);
 		if (!pblock) {

fs/jfs/jfs_metapage.c static int metapage_writepage(struct pag · line 456

Quoted 7 lines
fs/jfs/jfs_metapage.c +1 -0
@@ -449,12 +450,16 @@ static int metapage_writepage(struct pag
 			goto dump_bio;
 
 		submit_bio(WRITE, bio);
+		nr_underway++;
 	}
 	if (redirty)
 		redirty_page_for_writepage(wbc, page);

+ else
+ set_page_writeback(page);

fs/jfs/jfs_metapage.c static int metapage_writepage(struct pag · line 460

Quoted 4 lines
fs/jfs/jfs_metapage.c +1 -0
 	unlock_page(page);
 
+	if (nr_underway == 0)

+ if (nr_underway == 0 && redirty == 0)

fs/jfs/jfs_metapage.c static int metapage_writepage(struct pag · line 465

Quoted 5 lines
fs/jfs/jfs_metapage.c +2 -0
+		end_page_writeback(page);
+
 	return 0;
 add_failed:
 	/* We should never reach here, since we're only adding one vec */

Otherwise looks pretty good.

A message that is not in the archive (sent off-list or not yet received): E1J8RJw-0001ge-DP@localhost

#7 lore raw
Quoted 22 lines · Fengguang Wu
Quoted 14 lines · Dave Kleikamp

---

diff -Nurp linux-2.6.24-rc6-git5/fs/jfs/jfs_metapage.c linux/fs/jfs/jfs_metapage.c

fs/jfs/jfs_metapage.c +1 -0
@@ -360,6 +360,7 @@ static int metapage_writepage(struct pag
 	struct metapage *mp;
 	int redirty = 0;
 	sector_t lblock;
+	int nr_underway = 0;
 	sector_t pblock;
 	sector_t next_block = 0;
 	sector_t page_start;

fs/jfs/jfs_metapage.c static int metapage_writepage(struct pag · line 374

Quoted 3 lines
fs/jfs/jfs_metapage.c +0 -0
@@ -371,6 +372,7 @@ static int metapage_writepage(struct pag
 		     (PAGE_CACHE_SHIFT - inode->i_blkbits);
 	BUG_ON(!PageLocked(page));
 	BUG_ON(PageWriteback(page));

This line should be moved below:

Quoted 1 line

fs/jfs/jfs_metapage.c static int metapage_writepage(struct pag · line 375

Quoted 1 line
fs/jfs/jfs_metapage.c +1 -0
+	set_page_writeback(page);

No. set_page_writeback() needs to be called before submit_bio() is called.

I don't think there is any harm in calling set_page_writeback(), redirty_page_for_writeback() and end_page_writeback() in the case where there is no I/O to submit, and some dirty data cannot be written. It is consistent with what happens in __block_write_full_page().

It's also possible that some part of the page was written, and another part cannot be, causing the page to be redirtied.

Quoted 43 lines
Quoted 25 lines
fs/jfs/jfs_metapage.c +3 -3
 	for (offset = 0; offset < PAGE_CACHE_SIZE; offset += PSIZE) {
 		mp = page_to_mp(page, offset);
@@ -413,11 +415,10 @@ static int metapage_writepage(struct pag
 			if (!bio->bi_size)
 				goto dump_bio;
 			submit_bio(WRITE, bio);
+			nr_underway++;
 			bio = NULL;
-		} else {
-			set_page_writeback(page);
+		} else
 			inc_io(page);
-		}
 		xlen = (PAGE_CACHE_SIZE - offset) >> inode->i_blkbits;
 		pblock = metapage_get_blocks(inode, lblock, &xlen);
 		if (!pblock) {
@@ -449,12 +450,16 @@ static int metapage_writepage(struct pag
 			goto dump_bio;
 
 		submit_bio(WRITE, bio);
+		nr_underway++;
 	}
 	if (redirty)
 		redirty_page_for_writepage(wbc, page);
(quoted diff) +2 -0
+       else
+               set_page_writeback(page);

fs/jfs/jfs_metapage.c static int metapage_writepage(struct pag · line 460

Quoted 4 lines
fs/jfs/jfs_metapage.c +1 -0
 	unlock_page(page);
 
+	if (nr_underway == 0)

+ if (nr_underway == 0 && redirty == 0)

fs/jfs/jfs_metapage.c static int metapage_writepage(struct pag · line 465

Quoted 5 lines
fs/jfs/jfs_metapage.c +2 -0
+		end_page_writeback(page);
+
 	return 0;
 add_failed:
 	/* We should never reach here, since we're only adding one vec */

Otherwise looks pretty good.

Signature · 2 lines
David Kleikamp
IBM Linux Technology Center
#8 lore raw
Quoted 24 lines · Dave Kleikamp
Quoted 22 lines · Fengguang Wu
Quoted 14 lines · Dave Kleikamp

---

diff -Nurp linux-2.6.24-rc6-git5/fs/jfs/jfs_metapage.c linux/fs/jfs/jfs_metapage.c

fs/jfs/jfs_metapage.c +1 -0
@@ -360,6 +360,7 @@ static int metapage_writepage(struct pag
 	struct metapage *mp;
 	int redirty = 0;
 	sector_t lblock;
+	int nr_underway = 0;
 	sector_t pblock;
 	sector_t next_block = 0;
 	sector_t page_start;

fs/jfs/jfs_metapage.c static int metapage_writepage(struct pag · line 374

Quoted 3 lines
fs/jfs/jfs_metapage.c +0 -0
@@ -371,6 +372,7 @@ static int metapage_writepage(struct pag
 		     (PAGE_CACHE_SHIFT - inode->i_blkbits);
 	BUG_ON(!PageLocked(page));
 	BUG_ON(PageWriteback(page));

This line should be moved below:

Quoted 4 lines
Quoted 1 line

fs/jfs/jfs_metapage.c static int metapage_writepage(struct pag · line 375

Quoted 1 line
fs/jfs/jfs_metapage.c +1 -0
+	set_page_writeback(page);

No. set_page_writeback() needs to be called before submit_bio() is called.

Ah yes.

Quoted 7 lines

I don't think there is any harm in calling set_page_writeback(), redirty_page_for_writeback() and end_page_writeback() in the case where there is no I/O to submit, and some dirty data cannot be written. It is consistent with what happens in __block_write_full_page().

It's also possible that some part of the page was written, and another part cannot be, causing the page to be redirtied.

You are right. I revisited the code and there's nothing wrong with your patch :-)

Regards,
Fengguang

A message that is not in the archive (sent off-list or not yet received): E1J8UbJ-0007Be-E3@localhost

#10 lore raw
Quoted 17 lines · Fengguang Wu
Quoted 8 lines · Dave Kleikamp
Quoted 2 lines · Fengguang Wu

This line should be moved below:

fs/jfs/jfs_metapage.c static int metapage_writepage(struct pag · line 375

Quoted 1 line
fs/jfs/jfs_metapage.c +1 -0
+	set_page_writeback(page);

No. set_page_writeback() needs to be called before submit_bio() is called.

Ah yes.

Quoted 5 lines

I don't think there is any harm in calling set_page_writeback(), redirty_page_for_writeback() and end_page_writeback() in the case where there is no I/O to submit, and some dirty data cannot be written. It is consistent with what happens in __block_write_full_page().

Quoted 5 lines
Quoted 2 lines

It's also possible that some part of the page was written, and another part cannot be, causing the page to be redirtied.

You are right. I revisited the code and there's nothing wrong with your patch :-)

Fengguang,

Thank you for all your help with this bug. I've been on vacation and hadn't had much time to look at it. We'd probably still be scratching our heads wondering where the problem was without your hard work.

Shaggy

Quoted 4 lines

Regards,
Fengguang

Signature · 2 lines
David Kleikamp
IBM Linux Technology Center