[PATCH] rd: Preserve the dirty bit in init_page_buffers()

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Andrew Morton <akpm@...>
Cc: Nick Piggin <nickpiggin@...>, Christian Borntraeger <borntraeger@...>, <linux-mm@...>, <linux-kernel@...>, Martin Schwidefsky <schwidefsky@...>, Theodore Ts'o <tytso@...>
Date: Monday, October 15, 2007 - 6:40 pm

The problem:  When we are trying to free buffers try_to_free_buffers()
will look at ramdisk pages with clean buffer heads and remove the
dirty bit from the page.  Resulting in ramdisk pages with data that get
removed from the page cache.  Ouch!

Buffer heads appear on ramdisk pages when a filesystem calls
__getblk() which through a series of function calls eventually calls
init_page_buffers().

So to fix the mismatch between buffer head and page state this patch
modifies init_page_buffers() to transfer the dirty bit from the page to
the buffer heads like we currently do for the uptodate bit.

This patch is safe as only __getblk calls init_page_buffers, and
there are only two implementations of block devices cached in the
page cache.  The generic implementation in block_dev.c and the
implementation in rd.c.

The generic implementation of block devices always does everything
in terms of buffer heads so it always has buffer heads allocated
before a page is marked dirty so this change does not affect it.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
 fs/buffer.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 75b51df..8b87beb 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -972,6 +972,7 @@ init_page_buffers(struct page *page, struct block_device *bdev,
 	struct buffer_head *head = page_buffers(page);
 	struct buffer_head *bh = head;
 	int uptodate = PageUptodate(page);
+	int dirty = PageDirty(page);
 
 	do {
 		if (!buffer_mapped(bh)) {
@@ -980,6 +981,8 @@ init_page_buffers(struct page *page, struct block_device *bdev,
 			bh->b_blocknr = block;
 			if (uptodate)
 				set_buffer_uptodate(bh);
+			if (dirty)
+				set_buffer_dirty(bh);
 			set_buffer_mapped(bh);
 		}
 		block++;
-- 
1.5.3.rc6.17.g1911

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH resend] ramdisk: fix zeroed ramdisk pages on memory p..., Christian Borntraeger, (Mon Oct 15, 4:28 am)
Re: [PATCH resend] ramdisk: fix zeroed ramdisk pages on memo..., Eric W. Biederman, (Mon Oct 15, 11:14 pm)
Re: [PATCH resend] ramdisk: fix zeroed ramdisk pages on memo..., Eric W. Biederman, (Tue Oct 16, 12:57 am)
[patch][rfc] rewrite ramdisk, Nick Piggin, (Tue Oct 16, 3:47 am)
Re: [patch][rfc] rewrite ramdisk, Eric W. Biederman, (Wed Oct 17, 6:30 am)
Re: [patch][rfc] rewrite ramdisk, Nick Piggin, (Wed Oct 17, 8:49 am)
Re: [patch][rfc] rewrite ramdisk, Eric W. Biederman, (Wed Oct 17, 2:45 pm)
Re: [patch][rfc] rewrite ramdisk, Nick Piggin, (Wed Oct 17, 9:06 pm)
Re: [patch][rfc] rewrite ramdisk, Theodore Tso, (Tue Oct 16, 5:28 pm)
Re: [patch][rfc] rewrite ramdisk, Nick Piggin, (Tue Oct 16, 6:08 pm)
Re: [patch][rfc] rewrite ramdisk, Eric W. Biederman, (Tue Oct 16, 7:48 pm)
Re: [patch][rfc] rewrite ramdisk, Nick Piggin, (Tue Oct 16, 8:28 pm)
Re: [patch][rfc] rewrite ramdisk, Eric W. Biederman, (Tue Oct 16, 9:13 pm)
Re: [patch][rfc] rewrite ramdisk, Nick Piggin, (Tue Oct 16, 9:47 pm)
Re: [patch][rfc] rewrite ramdisk, Eric W. Biederman, (Tue Oct 16, 5:08 am)
Re: [patch][rfc] rewrite ramdisk, Jan Engelhardt, (Tue Oct 16, 3:52 am)
Re: [patch][rfc] rewrite ramdisk, Nick Piggin, (Tue Oct 16, 4:07 am)
Re: [patch][rfc] rewrite ramdisk, Jan Engelhardt, (Tue Oct 16, 4:17 am)
Re: [patch][rfc] rewrite ramdisk, Nick Piggin, (Tue Oct 16, 4:26 am)
Re: [patch][rfc] rewrite ramdisk, Jan Engelhardt, (Tue Oct 16, 4:53 am)
Re: [PATCH resend] ramdisk: fix zeroed ramdisk pages on memo..., Christian Borntraeger, (Mon Oct 15, 5:05 am)
Re: [PATCH resend] ramdisk: fix zeroed ramdisk pages on memo..., Eric W. Biederman, (Mon Oct 15, 2:38 pm)
Re: [PATCH resend] ramdisk: fix zeroed ramdisk pages on memo..., Eric W. Biederman, (Mon Oct 15, 6:37 pm)
[PATCH] rd: Preserve the dirty bit in init_page_buffers(), Eric W. Biederman, (Mon Oct 15, 6:40 pm)
Re: [PATCH] rd: Preserve the dirty bit in init_page_buffers(), Eric W. Biederman, (Tue Oct 16, 5:35 am)
[PATCH] rd: Mark ramdisk buffers heads dirty, Eric W. Biederman, (Mon Oct 15, 6:42 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Nick Piggin, (Tue Oct 16, 4:19 am)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Eric W. Biederman, (Tue Oct 16, 3:06 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Nick Piggin, (Tue Oct 16, 6:06 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Christian Borntraeger, (Tue Oct 16, 4:48 am)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Christian Borntraeger, (Tue Oct 16, 3:56 am)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Christian Borntraeger, (Wed Oct 17, 12:14 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Eric W. Biederman, (Wed Oct 17, 1:57 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Christian Borntraeger, (Wed Oct 17, 5:48 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Eric W. Biederman, (Wed Oct 17, 6:22 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Christian Borntraeger, (Thu Oct 18, 5:26 am)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Eric W. Biederman, (Fri Oct 19, 6:46 pm)
[PATCH] rd: Use a private inode for backing storage, Eric W. Biederman, (Fri Oct 19, 6:51 pm)
Re: [PATCH] rd: Use a private inode for backing storage, Nick Piggin, (Sun Oct 21, 12:28 am)
Re: [PATCH] rd: Use a private inode for backing storage, Eric W. Biederman, (Sun Oct 21, 1:10 am)
Re: [PATCH] rd: Use a private inode for backing storage, Eric W. Biederman, (Sun Oct 21, 2:48 am)
Re: [PATCH] rd: Use a private inode for backing storage, Eric W. Biederman, (Sun Oct 21, 1:56 pm)
Re: [PATCH] rd: Use a private inode for backing storage, Christian Borntraeger, (Sun Oct 21, 3:28 am)
Re: [PATCH] rd: Use a private inode for backing storage, Eric W. Biederman, (Sun Oct 21, 4:23 am)
Re: [PATCH] rd: Use a private inode for backing storage, Eric W. Biederman, (Sun Oct 21, 2:39 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Chris Mason, (Wed Oct 17, 3:14 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Eric W. Biederman, (Wed Oct 17, 4:29 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Chris Mason, (Wed Oct 17, 4:54 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Eric W. Biederman, (Wed Oct 17, 5:30 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Chris Mason, (Wed Oct 17, 6:58 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Eric W. Biederman, (Wed Oct 17, 7:28 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Chris Mason, (Wed Oct 17, 8:03 pm)
[RFC][PATCH] block: Isolate the buffer cache in it's own map..., Eric W. Biederman, (Wed Oct 17, 11:59 pm)
Re: [RFC][PATCH] block: Isolate the buffer cache in it's own..., Eric W. Biederman, (Fri Oct 19, 5:35 pm)
Re: [RFC][PATCH] block: Isolate the buffer cache in it's own..., Eric W. Biederman, (Fri Oct 19, 5:27 pm)
Re: [RFC][PATCH] block: Isolate the buffer cache in it's own..., Eric W. Biederman, (Sun Oct 21, 12:53 am)
Re: [RFC][PATCH] block: Isolate the buffer cache in it's own..., Eric W. Biederman, (Sun Oct 21, 3:09 am)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Eric W. Biederman, (Wed Oct 17, 11:27 pm)
Re: [PATCH] rd: Mark ramdisk buffers heads dirty, Eric W. Biederman, (Tue Oct 16, 5:22 am)